package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.ReturnRecordDAO;
import com.zerosky.crm.po.ReturnRecord;
import com.zerosky.crm.service.ReturnRecordService;
import com.zerosky.crm.util.PageInfo;

/**
 * Returnrecord业务逻辑实现类
 * 
 * @author hugy;
 * @since 2017-06-08
 *
 */
@Service(value="returnRecordService")
public class ReturnRecordServiceImpl implements ReturnRecordService {

	@Autowired
	private ReturnRecordDAO returnrecordDAO; // Returnrecord数据接口

	/**
	 * Returnrecord列表
	 * 
	 * @author hugy;
	 * @since 2017-06-08
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<ReturnRecord> getReturnRecordList(Map map) {
		return returnrecordDAO.getReturnRecordList(map);
	}

	/**
	 * 通过主键查找Returnrecord实体
	 * 
	 * @param id
	 *            Returnrecord主键
	 * @author hugy;
	 * @since 2017-06-08
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public ReturnRecord getReturnRecordById(String id) {
		return returnrecordDAO.getReturnRecordById(id);
	}

	/**
	 * 保存Returnrecord
	 * 
	 * @param Returnrecord
	 *            实体对象, operation 操作类型
	 * @author hugy;
	 * @since 2017-06-08
	 */
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void saveReturnRecord(ReturnRecord returnrecord, String operation) throws Exception {
		if ("新增".equalsIgnoreCase(operation)) {
			returnrecordDAO.addReturnRecord(returnrecord);
		} else if ("修改".equalsIgnoreCase(operation)) {
			returnrecordDAO.updateReturnRecord(returnrecord);
		}
	}

	/**
	 * 删除Returnrecord
	 * 
	 * @param idArray
	 *            Returnrecord主键数组
	 * @author hugy;
	 * @since 2017-06-08
	 */
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteReturnRecordById(String id) throws Exception {
		returnrecordDAO.deleteReturnRecordById(id);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<ReturnRecord> getPageInfoList(Map map, PageInfo<ReturnRecord> page) {
		int begin = ((page.getPageNo() - 1) * page.getPageSize());
		int pageSize = page.getPageSize();

		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<ReturnRecord> list = returnrecordDAO.getReturnRecordList(map);
		page.setList(list);

		int count = returnrecordDAO.countReturnRecord(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}
}
